{% extends 'base.html' %}
{% block title %}
    角色列表
{% endblock %}

{% block breadcrumb %}
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-home"></i> Home</a></li>
        <li>权限系统</li>
        <li class="active">角色列表</li>
    </ol>
{% endblock %}
{% block status %}
    角色列表
{% endblock %}
{% block content %}
    <div class="row">
        <div href="#" class="col-lg-12" style="margin: 0 20px 10px 0;font-size: 12px">
            <input type="text" size="30" placeholder="搜索" style="height: 30px">
            <select onchange="ChangeType(this)" id="idc-search" style="height: 30px;width: 150px">
                <option value="">以 角色名称</option>
                <option disabled>----------</option>
                {% for role in data %}
                    <option value="{{ role.id }}">{{ role.group_name }}</option>
                {% endfor %}
            </select>
            <button class="btn btn-inline btn-success" style="height: 30px;font-size: 12px">搜索</button>
            <a href="/auth/cmdb/add/" class="pull-right">
                <i class="glyphicon glyphicon-plus"></i>添加角色
            </a>
        </div>
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-body">
                    <table width="100%" class="table table-striped table-hover" id="dataTables-example">
                        <thead>
                            <tr style="color: white;background: #6f7e95;">
                                <th><input type="checkbox" id="checkAll"></th>
                                <th>角色名称</th>
                                <th>角色描述</th>
                                <th>成员人数</th>
                                <th style="width: 150px">状态</th>
                                <th><li class="glyphicon glyphicon-cog"></li>&nbsp;管理操作</th>
                            </tr>
                            {% for i in data %}
                              {% ifequal i.enable 1%}
                                <tr>
                                    <td><input type="checkbox" name="_dataCheckBox"></td>
                                    <td><a href="/auth/cmdb/group_auth_edit/{{ i.id }}/">{{ i.group_name }}</a></td>
                                    <td>{{ i.explanation }}</td>
                                    <td>{% for k,v in group_user_count.items %} {% if k == i.id %}{{ v }}{% endif %}{% endfor %}</td>
                                    {% if i.enable %}
                                        <td><a href="/auth/cmdb/status/{{ i.id }}/" class="voilet_restart"><span class="glyphicon glyphicon-ok" aria-hidden="true" style="color:#2ad49e"></span></a> </td>
                                    {% else %}
                                        <td><a href="/auth/cmdb/status/{{ i.id }}/" class="voilet_restart"><span class="glyphicon glyphicon-remove" aria-hidden="true" style="color:#ff6846"></span> </a></td>
                                    {% endif %}
                                    <td id="{{ i.id }}"> <a href="/auth/cmdb/group_auth/{{ i.id }}/" class="select_node"  >权限管理</a> |
                                        <a href="/auth/cmdb/group_user/{{ i.id }}/" class="select_node">成员管理</a> |
                                        <a href="/auth/cmdb/group_auth_edit/{{ i.id }}/" class="select_node"><li class="glyphicon glyphicon-pencil" style="color:#2ad49e"></li>修改</a> |
                                        <a href="javascritp:void(0);" onclick="Delete(this)"><li class="glyphicon glyphicon-trash" style="color:#ff6846"></li>删除</a>
                                    </td>
                                </tr>
                              {% endifequal %}
                            {% endfor %}
                        </thead>
                    </table>
                </div>
                <!-- /.panel-body -->
            </div>
        </div>
       <!-- /.col-lg-12 -->
    </div>
    <div class="col-sm-5 pull-left" id="action_buttons" style="font-size: 12px">
      <span id="selected_count">0</span>&nbsp;选择 &nbsp;
      <button class="btn btn-default btn-sm" disabled>启用</button>
      <button class="btn btn-default btn-sm" disabled>禁用</button>
      <button class="btn btn-default btn-sm" disabled>修改</button>
      <button class="btn btn-default btn-sm" disabled>删除</button>
    </div>
    <div class="pull-right" style="margin-right: 20px">
        {{ count }}&nbsp;角色
    </div>
{% endblock %}

{% block action %}
    <script>
        function Delete(doc) {
            var rid = $(doc).parent().attr('id');
            $.ajax({
                url:'/auth/cmdb/delete_auth/',
                data:{"rid":rid},
                type:"POST",
                success:function (callback) {
                    if(callback["status"]=="ok"){
                        $(doc).parents('tr').remove();
                    }
                }
            })
        }
    </script>
{% endblock %}